package com.unisound.tracelog.client.core.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

public class TraceLogListeners {
    private static final Logger LOGGER = LoggerFactory.getLogger(TraceLogListeners.class);
    private List<TraceLogListener> traceLogListeners = new ArrayList<>();

    public void register(TraceLogListener traceLogListener) {
        traceLogListeners.add(traceLogListener);
    }

    public void publishSpanEvent(SpanEvent spanEvent) {
        for (TraceLogListener traceLogListener : traceLogListeners) {
            try {
                traceLogListener.listenerSpanEvent(spanEvent);
            } catch (Throwable e) {
                LOGGER.error("publishSpanEvent error", e);
            }
        }
    }

    public void publishTagEvent(TagEvent tagEvent) {
        for (TraceLogListener traceLogListener : traceLogListeners) {
            try {
                traceLogListener.listenerTagEvent(tagEvent);
            } catch (Throwable e) {
                LOGGER.error("publishTagEvent error", e);
            }
        }
    }

}
